#!/bin/bash
# 传参检测
##################################################################
nethosts=`cat /etc/hosts |grep -v ^$|egrep -v "127.0.0.1|localhost"|awk  '{print $1}'`
#node节点上的密码，建议密码保持一致
rootpasswd="1adgasdav"
###################################################################
# 在deploy机器做其他node的ssh免密操作
echo ${nethosts}
ssh(){
for i in  ${nethosts}
do
    echo "====================== ${i} ======================";
   echo ${i}
    if [[ ${USER} == 'root' ]];then
        [ ! -f /${USER}/.ssh/id_rsa ] &&\
        ssh-keygen -t rsa -P '' -f /${USER}/.ssh/id_rsa &>/dev/null
    else
        [ ! -f /home/${USER}/.ssh/id_rsa ] &&\
        ssh-keygen -t rsa -P '' -f /home/${USER}/.ssh/id_rsa &>/dev/null
    fi
    sshpass -p ${rootpasswd} ssh-copy-id -o StrictHostKeyChecking=no ${USER}@${i} &>/dev/null
done
}
ssh